package com.yzh.pinboard.CustomView;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yzh.pinboard.R;

/**
 * Created by Administrator on 2017/3/13.
 */

public class MenuView extends LinearLayout implements View.OnClickListener {


    public MenuView(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_menu, this);
        final GridLayout gridLayout = (GridLayout) view.findViewById(R.id.gv_menu);
        CheckBox imageView = (CheckBox) view.findViewById(R.id.iv_menu);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                gridLayout.setVisibility(gridLayout.getVisibility() == VISIBLE ? GONE : VISIBLE);
            }
        });

        LinearLayout llSave = (LinearLayout) view.findViewById(R.id.save_board);
        LinearLayout llOpen = (LinearLayout) view.findViewById(R.id.open_board);
        LinearLayout llChange = (LinearLayout) view.findViewById(R.id.change_background);
        LinearLayout llClose = (LinearLayout) view.findViewById(R.id.close_board);
        llSave.setOnClickListener(this);
        llOpen.setOnClickListener(this);
        llChange.setOnClickListener(this);
        llClose.setOnClickListener(this);
    }

    public MenuView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);


    }

    public void setMenuListener(MenuListener menuListener) {
        mMenuListener = menuListener;
    }

    private MenuListener mMenuListener;

    @Override
    public void onClick(View v) {
        if (mMenuListener == null) {
            return;
        }
        int i = v.getId();
        if (i == R.id.save_board) {
            mMenuListener.saveBoard();
        } else if (i == R.id.open_board) {
            mMenuListener.openBoard();

        } else if (i == R.id.change_background) {
            mMenuListener.changeBackground();
        } else if (i == R.id.close_board) {
            mMenuListener.closeBoard();

        }
    }

    public interface MenuListener {
        void saveBoard();

        void openBoard();

        void changeBackground();

        void closeBoard();
    }
}
